package cate.game.play.skill.passive.awaken;

import cate.common.table.d.GDSkill;
import cate.game.play.base.TargetFilterParam;
import cate.game.play.base.TargetSelector;
import cate.game.play.config.PlayCfgArgs;
import cate.game.play.fighter.Fighter;
import cate.game.play.proce.action.ctx.ActionCtx;
import cate.game.play.proce.action.ctx.SkillActionCtx;
import cate.game.play.skill.passive.PassiveHandler;
import easy.java.struct.ref.DoubleRef;

/**
 * 效果4：觉醒状态下受致死伤害时(斩杀和真实伤害除外)，提升全体友方单位50%觉醒值，该效果回合内每个单位至多收益1次；
 * 效果5： 觉醒状态结束后提升随机1个友方单位25%觉醒值，该效果回合内每个单位至多收益2次
 * 效果6： 觉醒状态下受击时为至多1个友方单位附加【壁垒】2回合(不可驱散)，
 *               携带该状态的目标受击时免疫基于发起者300%灵能防御的伤害，并将免疫伤害以70%效率反馈给攻击者
 */
public class 邪铸壁垒PH extends PassiveHandler {

	private int 致死buff;

	private int 结束buff;

	private int 受击buff;

	//致死buff=？？&结束buff=？？&受击buff=？？
	@Override
	public void parse(String code) {
		PlayCfgArgs args = new PlayCfgArgs(code);
		致死buff = args.getInt("致死buff", 0);
		结束buff = args.getInt("结束buff", 0);
		受击buff = args.getInt("受击buff", 0);
	}

	@Override
	public void adjustDeadlyDamage(ActionCtx action, Fighter actor, int reason, DoubleRef doubleRef) {
		if (skill.owner.isDead() || !skill.owner.status.isAwaken()) {
			return;
		}
		for (Fighter target : skill.owner.getFightTeam().getFriends(skill.owner)) {
			target.buff.tryAddByTid(action, skill.owner, 致死buff);
		}
	}

	@Override
	public void onAwaken(ActionCtx action, boolean start) {
		if (start) {
			return;
		}
		TargetFilterParam param = new TargetFilterParam().scopeSet(GDSkill.Scope.FRIENDS);
		Fighter target = TargetSelector.findOne(skill.owner, action.getTeamVs(), param);
		if (target != null) {
			target.buff.tryAddByTid(action, skill.owner, 结束buff);
		}
	}


	private boolean addSufferBuff;

	@Override
	public void onRoundBegin(ActionCtx action) {
		addSufferBuff = false;
	}

	@Override
	public void afterSufferOneAttack(SkillActionCtx action, long totalDamage, boolean strike) {
		if (skill.owner.isDead() || !skill.owner.status.isAwaken()) {
			return;
		}
		if (addSufferBuff) {
			return;
		}
		TargetFilterParam param = new TargetFilterParam().scopeSet(GDSkill.Scope.FRIENDS);
		Fighter target = TargetSelector.findOne(skill.owner, action.getTeamVs(), param);
		if (target != null) {
			target.buff.tryAddByTid(action, skill.owner, 受击buff);
			addSufferBuff = true;
		}
	}
}
